<template>
  <div id="app">
    <!-- 计算属性可以简化 template 中的代码 -->
    <!-- <h1>{{ arr }}</h1> -->
    <h1>{{ $store.getters.arr }}</h1>
    <!-- <ul>
      <li v-for="item in arr" :key="item">{{ item }}</li>
    </ul> -->
    <ul>
      <li v-for="item in arr" :key="item">{{ item }}</li>
    </ul>
    <h1>根组件 {{ $store.state.count }}</h1>
    <!-- 不要用双向绑定来绑定 vuex 中的数据 -->
    <!-- <input v-model="$store.state.count" type="text"> -->
    <!-- 正确做法: 单向绑定 value -->
    <!-- <input @input="changeCount(+$event.target.value)" :value="$store.state.count" type="text"> -->
    <input @input="change" :value="$store.state.count" type="text">
    <add-item></add-item>
    <hr>
    <sub-item></sub-item>
  </div>
</template>

<script>
import AddItem from './components/add-item.vue'
import SubItem from './components/sub-item.vue'
import { mapMutations, mapGetters } from 'vuex'

export default {
  name: 'app',
  data: function () {
    return {
      
    }
  },
  components: {
    AddItem,
    SubItem
  },
  methods: {
    ...mapMutations(['changeCount']),
    change(e) {
      // console.log(+e.target.value)
      // this.$store.commit('changeCount', +e.target.value)
      this.changeCount(e.target.value)
    }
  },
  computed: {
    ...mapGetters(['arr'])
    // arr() {
    //   return this.$store.state.list.filter(item => item > 5)
    // }
  }
}
</script>

<style>
#app {
  width: 600px;
  margin: 20px auto;
  border: 3px solid #ccc;
  border-radius: 3px;
  padding: 10px;
}
</style>